﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QLPM.DAO
{
    public class Function
    {
        public static string Convert_date(string str, string format_star, string format_end)
        {
            string str_date = "";
            char[] arrSeparator = null;
            arrSeparator = new char[] { '/', '-'};
            string[] arr = str.Split(arrSeparator);
            string dd = "";
            string mm = "";
            string yy = "";
            switch (format_star.ToLower())
            {
                case "dd/mm/yyyy":
                    dd = arr[0];
                    mm = arr[1];
                    yy = arr[2];
                    break;
                case "mm/dd/yyyy":
                    dd = arr[1];
                    mm = arr[0];
                    yy = arr[2];
                    break;
                case "yyyy/mm/dd":
                    dd = arr[2];
                    mm = arr[1];
                    yy = arr[0];
                    break;
                default:
                    return str;
            }

            switch (format_end.ToLower())
            {
                case "dd/mm/yyyy":
                    str_date = dd + "/" + mm + "/" + yy;
                    break;
                case "mm/dd/yyyy":
                    str_date = mm + "/" + dd + "/" + yy;
                    break;
                case "yyyy/mm/dd":
                    str_date = yy + "/" + mm + "/" + dd;
                    break;
                default:
                    return str;
            }
            return str_date;
        }
    }
}
